home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / basic / ace24dist.lha / ace24.lha / utils / autonum / autonum.b
Text File  |  1996-09-10  |  3KB  |  157 lines

  1. {*
  2. ** - This program produces a paged and line-numbered document
  3. **   for ACE.DOC format files.
  4. **
  5. ** Author: David J Benn
  6. **   Date: 4th,10th,11th,14th,15th January 1994,
  7. **      30th July 1994,
  8. **      3rd October 1994
  9. *}
  10.  
  11. DEFINT a-z
  12.  
  13. CONST MAX=100,STARTCOL=45,NUMSIZE=4
  14.  
  15. pagelen=62
  16.  
  17. DIM content(MAX),page(MAX),section(MAX)
  18.  
  19. if argcount<>2 and argcount<>3 then
  20.   print "usage: ";arg$(0);" source target [page-length (default=62)]"
  21.   print "   eg: ";arg$(0);" ace.fmt ace.doc" 
  22.   print "       ";arg$(0);" ace.fmt ace.doc 59" 
  23.   stop
  24. end if
  25.  
  26. open "I",1,arg$(1)
  27.  
  28. if handle(1)=0& then 
  29.   print "Input file error!"
  30.   stop
  31. end if
  32.  
  33. open "O",2,arg$(2)
  34.  
  35. if handle(2)=0& then 
  36.   print "Output file error!"
  37.   close #1
  38.   stop
  39. end if
  40.  
  41. on break goto quit
  42. break on
  43.  
  44. print "Paginating ";arg$(1);"..."
  45.  
  46. open "O",#3,"tmp.doc"
  47.  
  48. if argcount=3 then pagelen=val(arg$(3))
  49.  
  50. linecount=0
  51. pagecount=1
  52.  
  53. '..paginate
  54. while not eof(1)
  55.   line input #1,x$
  56.   print #3,x$
  57.   ++linecount
  58.   if linecount = pagelen then
  59.     print #3," "
  60.     print #3,SPC(34);"- page";pagecount;"-"
  61.     print #3," "
  62.     print "Page";pagecount
  63.     ++pagecount
  64.     linecount=1
  65.   end if
  66. wend
  67.  
  68. '..need to finish off last page?
  69. if linecount < pagelen then
  70.    for i=linecount to pagelen
  71.      print #3," "
  72.    next
  73.    print #3,SPC(34);"- page";pagecount;"-"
  74.    print "Page";pagecount
  75. end if
  76.  
  77. close 1,3
  78.  
  79. print "Looking for section references..."
  80. open "I",1,"tmp.doc"
  81. line_num=0
  82. linecount=0
  83. pagecount=1
  84. refs=0
  85. x$=""
  86. while not eof(1) and instr(x$,"==")=0
  87.   print "-->";line_num
  88.   line input #1,x$
  89.   ++line_num
  90.   ++linecount
  91.   if linecount = pagelen+3 then
  92.      ++pagecount
  93.      linecount=1
  94.   end if
  95.   if instr(STARTCOL,x$,"%%") then 
  96.     content(refs) = line_num
  97.     ++refs
  98.   end if
  99. wend
  100. print "Number of section references found:";refs
  101.  
  102. print "Looking for sections..."
  103. count=0
  104. while not eof(1) 
  105.   line input #1,x$
  106.   ++line_num
  107.   ++linecount
  108.   if linecount = pagelen+3 then
  109.      ++pagecount
  110.      linecount=1
  111.   end if
  112.   if instr(x$,"$$") then
  113.     section(count) = line_num
  114.     page(count) = pagecount
  115.     ++count
  116.     print "Line";line_num;"= ";mid$(x$,3)
  117.   end if  
  118. wend
  119. close #1
  120.  
  121. print "Creating ";arg$(2);"..."
  122. open "I",1,"tmp.doc"
  123. linecount=0
  124. count=0
  125. while not eof(1)
  126.   line input #1,x$
  127.   if x$="" then x$=" " '..prevent raw EOS being sent to file! (ACE silliness)
  128.   ++linecount
  129.   print "Line";linecount
  130.   '..contents page entry?
  131.   if content(count) = linecount then
  132.     linenum$=mid$(str$(section(count)),2)
  133.     while len(linenum$) < NUMSIZE
  134.       linenum$ = "."+linenum$
  135.     wend
  136.     y$=mid$(x$,1,instr(STARTCOL,x$,"%%")-1)+linenum$
  137.     pg$=str$(page(count))
  138.     y$=y$+space$(6-len(pg$))+pg$
  139.     print #2,y$
  140.     print "Section: ";y$
  141.     ++count
  142.   else
  143.     '..new section?
  144.     if instr(x$,"$$") then
  145.       section_heading$=mid$(x$,3)
  146.       print #2,section_heading$
  147.       print section_heading$
  148.     else
  149.       '..other line
  150.       print #2,x$
  151.     end if
  152.   end if
  153. wend
  154.  
  155. quit:
  156. close 1,2,3
  157.